<template>
  <page-header-wrapper>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <a-row type="flex" justify="space-between">
        <a-col>
          <span class="info">{{defultForm.entName}}</span>
        </a-col>
        <a-col>
          <a-button class="btn" @click="back">返回</a-button>
        </a-col>
      </a-row>
    </a-card>
    <a-card :bordered="false">
      <h3 class="part-title">需求基本信息</h3>
      <div class="pl-40">
        <ul>
          <li class="list-info">
            <span>需求名称：</span>{{ defultForm.demandProductName }}
          </li>
          <li class="list-info">
            <span>产品同义名称：</span>{{ defultForm.productSynonymName }}
          </li>
          <li class="list-info">
            <span>产品类别：</span>
            <span style="color:#000" v-if="defultForm.productOneCategoryName">
              {{ defultForm.productOneCategoryName }}
            </span>
            <span style="color:#000" v-if="defultForm.productSecondCategoryName">
              - {{ defultForm.productSecondCategoryName }}
            </span>
            <span style="color:#000" v-if="defultForm.productThirdCategory">
              {{ defultForm.productThirdCategory }}
            </span>
          </li>
          <li class="list-info">
            <span>规格型号：</span>{{ defultForm.productSpec }}
          </li>
          <li class="list-info">
            <span>概述：</span>{{ defultForm.demandDetails }}
          </li>
          <li class="list-info">
            <span>预算价格：</span>{{ defultForm.price }}元
          </li>
          <li class="list-info">
            <span>发布时间：</span>{{ defultForm.createTime }}
          </li>
          <li class="list-info">
            <span>截止时间：</span>
            <span style="color:#000" v-if="defultForm.isLongTime == 0">{{ defultForm.expirationDate }}</span>
            <span style="color:#000" v-if="defultForm.isLongTime==1">长期有效</span>
          </li>
        </ul>
      </div>
      <h3 class="part-title">联系方式</h3>
      <div class="pl-40">
        <ul>
          <li class="list-info">
            <span>产品需求商企业名称：</span>{{ defultForm.entName }}
          </li>
          <li class="list-info">
            <span>企业地址：</span>{{ entList.entAddress }}
          </li>
          <li class="list-info">
            <span>企业网址：</span>{{ entList.webAddress }}
          </li>
          <li class="list-info">
            <span>联系人：</span>{{ defultForm.contacts }}
          </li>
          <li class="list-info">
            <span>手机号码：</span>{{ defultForm.phone }}
          </li>
          <li class="list-info">
            <span>电子邮箱：</span>{{ defultForm.email }}
          </li>
        </ul>
      </div>
      <div v-if="defultForm.auditStatus==3">
        <h3 class="part-title">审核不通过的原因</h3>
        <div class="pl-40">
          <ul>
            <li class="list-info">
              <span>原因：</span>
              {{defultForm.auditRemark}}
            </li>
          </ul>
        </div>
      </div>
      <div v-if="defultForm.auditStatus===1" style="margin-left: 40%; margin-top: 30px">
        <a-button type="primary" class="mr-50" @click="success">通过</a-button>
        <a-button type="danger" class="mr-50" @click="showModal">不通过</a-button>
      </div>
      <a-modal v-model="visible" title="审核退回" @ok="handleOk" :width="800">
        <!-- <a-form :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-form-item label="审核不通过原因:">
            <a-textarea v-model="form.desc" style="margin-left: 50px" :auto-size="{ minRows: 7, maxRows: 50 }" />
          </a-form-item>
        </a-form> -->
        <a-form-model :model="form" ref="form" :rules="rules">
          <a-form-model-item label="审核不通过原因:" prop="desc">
            <a-textarea v-model="form.desc" :auto-size="{ minRows: 7, maxRows: 50 }" />
          </a-form-model-item>
        </a-form-model>
      </a-modal>
    </a-card>
  </page-header-wrapper>
</template>
<script>
import { GetentBaseInfo } from '@/api/product.js'
import { GetDemandInfo, DemandAudit } from '@/api/MaterialDemand'
export default {
  data() {
    return {
      demandID: '',
      visible: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 15 },
      form: {
        desc: '',
      },
      rules: {
        desc: [
          {
            required: true,
            message: '请输入审核不通过原因',
            trigger: 'blur',
          },
        ],
      },
      defultForm: {},
      entList: {},
      entId: '',
    }
  },
  created() {
    console.log(this.$route.query.id)
    if (this.$route.query.id) {
      this.demandID = this.$route.query.id
      this.GetDemandInfo()
    }
  },
  methods: {
    back() {
      this.$router.back()
    },
    showModal() {
      this.visible = true
    },
    handleOk() {
      //   this.$refs.form.validate((valid) => {
      // ​    if (valid) {
      // // ​     that.entMerchantscheck()
      //       let auditStatus = 3;
      //       this.DemandAudit(auditStatus,this.form.desc)
      //          this.$message.success('审核处理完成！')
      // ​    } else {
      // ​     console.log('error submit!!')
      // ​     return false
      // ​    }
      //   })

      let that = this
      this.$refs.form.validate((valid) => {
        if (valid) {
          let auditStatus = 3
          this.DemandAudit(auditStatus, this.form.desc)
        } else {
          console.log('error submit!!')
          return false
        }
      })
      // this.visible = false

      // this.$router.back()
    },
    success() {
      var that = this
      this.$confirm({
        title: '您确定要通过此信息吗?',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          // 点击确定
          let auditStatus = 2
          that.form.desc = ''
          that.DemandAudit(auditStatus)
          that.$message.success('审核通过！')
        },
        onCancel() {
          // 点击取消
          console.log('Cancel')
        },
      })
    },
    //获取详情
    GetDemandInfo() {
      GetDemandInfo({ id: this.demandID }).then((res) => {
        console.log(res)
        if (res.code == 200) {
          this.defultForm = res.data
          this.entId = res.data.entId
          this.GetentBaseInfo()
        }
      })
    },
    GetentBaseInfo() {
      let _params = {
        id: this.entId,
      }
      GetentBaseInfo(_params).then((res) => {
        console.log(res)
        if (res.code == 200) {
          this.entList = res.data
        }
      })
    },

    //审核
    DemandAudit(auditStatus) {
      let _params = {
        demandId: this.demandID,
        auditRemark: this.form.desc,
        auditStatus,
        entId: this.entId
      }
      DemandAudit(_params).then((res) => {
        console.log(res)
        if (res.code == 200) {
          // this.$message.success('审核处理完成！')
          setTimeout(() => {
            this.$router.push('/infoVerify/NeedInfo/list')
          }, 50)
        }
      })
    },
  },
  mounted() {},
}
</script>
<style lang="less" scoped>
.info {
  font-family: 'Arial Negreta', 'Arial';
  font-weight: 700;
  font-style: normal;
  font-size: 16px;
  color: #333333;
}
.part-title {
  position: relative;
  font-weight: bold;
  height: 40px;
  background-color: #f5f7fa;
  padding-left: 10px;
  border-radius: 2px;
  line-height: 40px;
}
.part-title:before {
  content: '';
  height: 4px;
  width: 20px;
  position: absolute;
  bottom: 0;
  left: 24;
  background-color: #298ef5;
}
.list-info {
  border-bottom: 1px dashed #ebeef5;
  line-height: 24px;
  padding: 10px 0;
  color: #030303;
  span {
    color: #909399;
  }
}
</style>s